/**
 * @author zll
 */

//Accordian Initializer
function Accordian(d) {

	// get all the elements that have id as content
	l = $(d).children('div');
	c = [];

	for(var i = 0; i < l.length; i++) {
		h = l[i].id;
		if(h.substr(h.indexOf('-') + 1, h.length) == 'content') {
			c.push(h);
		}
	}

	//then search through headers
	for( i = 0; i < l.length; i++) {
		h = l[i].id;
		if(h.substr(h.indexOf('-') + 1, h.length) == 'header') {
			var d = $('#' + h.substr(0, h.indexOf('-')) + '-content');
			d.css('display', 'none');
			d.css('overflow', 'hidden');
			d.css('maxheight', d.outerHeight(true));
			h = $('#' + h);
			// set the onclick function for each header.
			h.click(function() {
				for( i = 0; i < c.length; i++) {
					cn = c[i];
					n = cn.substr(0, cn.indexOf('-'));
					if((n + '-header') == this.id) {
						$('#' + n + '-content').slideDown("fast");
						$(this).addClass('header_highlight');
					} else {
						$('#' + n + '-content').slideUp("fast");
						$('#' + n + '-header').removeClass('header_highlight');
					}
				}
			});
		}
	}
}